//
//  HNSH_HomeGoodsCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/23.
//

#import "HNSH_HomeGoodsCell.h"
#import "CJJTimerView.h"

@interface HNSH_HomeGoodsCell ()
/* bgView */
@property (nonatomic, strong) UIView *bgView;
/** 图片 */
@property (nonatomic, strong)UIImageView * imgView;
/** 名字 */
@property (nonatomic, strong)UILabel * nameLabel;
/** 送购物值*/
@property (nonatomic, strong)UILabel * sendJfLabel;
/** 价格 */
@property (nonatomic, strong)UILabel * priceLabel;

@end

@implementation HNSH_HomeGoodsCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appBGColor];
        self.contentView.backgroundColor = [UIColor appBGColor];
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_GoodsListModel *)model {
    _model = model;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.cover_url]];
    self.nameLabel.text = model.name;
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",[model.price doubleValue]];
    self.priceLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.priceLabel.text SelectContent:@"¥" CommonFont:self.priceLabel.font SpeFont:[UIFont systemFontOfSize:10] Color:self.priceLabel.textColor];
    
    self.sendJfLabel.hidden = [model.reward_amount doubleValue] <= 0;
    self.sendJfLabel.text = [NSString stringWithFormat:@" 送%.2f购物值 ",[model.reward_amount doubleValue]];
    if ([model.reward_integral doubleValue] > 0) {
        self.sendJfLabel.hidden = NO;
        self.sendJfLabel.text = [NSString stringWithFormat:@" 送%.2f冻结能量 ",[model.reward_integral doubleValue]];
    }
    
}

- (void)configUI {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.imgView];
    [self.bgView addSubview:self.nameLabel];
    [self.bgView addSubview:self.sendJfLabel];
    [self.bgView addSubview:self.priceLabel];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(0);
    }];
    
    CGFloat w = (kScreenWidth - 32) / 2.0;
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(w);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(self.imgView.mas_bottom).offset(10);
        make.height.mas_equalTo(20);
    }];

    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(4);
        make.height.mas_equalTo(22);
    }];

    [self.sendJfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(9);
        make.left.mas_equalTo(self.priceLabel);
        make.height.mas_equalTo(16);
    }];
}


//MARK: Getter Methods
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
        _bgView.layer.cornerRadius = 8.0f;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.backgroundColor = [UIColor grayColor];
    }
    return _imgView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.textColor = [UIColor appBlackLabelColor];
        _nameLabel.font = [UIFont boldSystemFontOfSize:14];
        _nameLabel.text = @"";
    }
    return _nameLabel;
}

- (UILabel *)sendJfLabel{
    if (!_sendJfLabel) {
        _sendJfLabel = [UILabel new];
        _sendJfLabel.text = @"";
        _sendJfLabel.textColor = [UIColor appGreenColor];
        _sendJfLabel.font = [UIFont systemFontOfSize:11];
        _sendJfLabel.textAlignment = NSTextAlignmentCenter;
        _sendJfLabel.layer.cornerRadius = 3.0f;
        _sendJfLabel.layer.masksToBounds = YES;
        _sendJfLabel.layer.borderColor = [[UIColor appGreenColor] CGColor];
        _sendJfLabel.layer.borderWidth = 1.0f;
    }
    return _sendJfLabel;
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [UILabel new];
        _priceLabel.text = @"";
        _priceLabel.textColor = [UIColor appOrangeLabelColor];
        _priceLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _priceLabel;
}

@end
